package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.DailyTotal;
import com.neusoft.elmboot.po.Orders;
import com.neusoft.elmboot.service.OrdersService;

@RestController
@RequestMapping("/orders")
public class OrdersController {

	@Autowired
	private OrdersService ordersService;
	
	@PostMapping("/")
	public int createOrders(Orders orders) throws Exception{
		return ordersService.createOrders(orders);
	}
	
	@GetMapping("/{orderId}")
	public Orders getOrdersById(Orders orders) throws Exception{
		return ordersService.getOrdersById(orders.getOrderId());
	}
	
	@GetMapping("/users/{userId}")
	public List<Orders> listOrdersByUserId(Orders orders) throws Exception{
		return ordersService.listOrdersByUserId(orders.getUserId());
	}
	
	@PutMapping("/{orderId}")
	public int updateOrderStatus(Orders orders)  throws Exception{
		return ordersService.updateOrderStatus(orders.getOrderId());
	}
	
	@PostMapping("/comment/{orderId}")
	public int saveComment(Orders orders) throws Exception{
		return ordersService.saveComment(orders);
	}
	
	@GetMapping("/comment/{orderId}")
	public String getComment(Orders orders) throws Exception{
		return ordersService.getComment(orders.getOrderId());
	}
	
	@GetMapping("/business/{businessId}")
	public List<Orders> listOrdersByBusinessId(Orders orders) throws Exception{
		return ordersService.listOrdersByBusinessId(orders.getBusinessId());
	}
	
	@GetMapping("/WeeklyTotalById")
	public List<DailyTotal> listWeeklyTotalById(String userId) throws Exception {
		return ordersService.listWeeklyTotalById(userId);
	}

	@GetMapping("/MonthlyTotalById")
	public List<DailyTotal> listMonthlyTotalById(String userId) throws Exception {
		return ordersService.listMonthlyTotalById(userId);
	}
	
	
	
	
}
